﻿using System;

namespace Numble
{
    class Player
    {
        #region Property
        private static int[] levels = new int[] { 1, 900, 800, 1000, 900, 800, 1000, 900, 800, 1000 }; //мисля че интервалите са къси
        private static int[] numbers = new int[] { 3, 3, 3, 4, 4, 4, 5, 5, 5, 6 };
        private static int level;
        public int Wait
        {
            get
            {
                return levels[level];
            }
        }
        public int Row { get; set; }
        public int Col { get; set; }
        public int Points { get; set; }
        private int Symbol { get; set; }
        public int LastSymbol { get; set; }
        public bool isShoot { get; set; }

        public int maxCol { get; set; }

        private static Random next = new Random();
        #endregion
        public Player(int row, int col, int newLevel)
        {
            this.Col = col / 2;
            this.maxCol = col;
            this.Row = row;
            level = newLevel - 1;
            this.Symbol = next.Next(1, numbers[level]); // струват ми се много числата за първо ниво 
        }

        public bool MovePlayer()
        {
            bool pressedSpace = this.Move();
            return pressedSpace;
        }

        public void Print()
        {
            Console.SetCursorPosition(0, this.Row - 1);
            Console.BackgroundColor = Color.GetColor(0);
            Console.Write(new string(' ', this.maxCol));
            Console.BackgroundColor = Color.GetColor(this.Symbol);
            Console.SetCursorPosition(this.Col, this.Row - 1);
            Console.Write(" ");
            Console.BackgroundColor = Color.GetColor(0);
        }

        public bool Move()
        {
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo inputKey = Console.ReadKey();
                if (inputKey.Key == ConsoleKey.LeftArrow)
                {
                    this.Col--;
                    if (this.Col < 0)
                    {
                        this.Col = 0;
                    }
                }
                else if (inputKey.Key == ConsoleKey.RightArrow)
                {
                    this.Col++;
                    if (this.Col > this.maxCol - 1)
                    {
                        this.Col = this.maxCol - 1;
                    }
                }
                if (inputKey.KeyChar == ' ')
                {
                    this.LastSymbol = this.Symbol;
                    this.Symbol = next.Next(1, numbers[level]);
                    this.isShoot = true;
                }
                return true;

            }
            return false;
        }

    }
}
